package com.lz.football.module.explore.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.model.goods.vo.PlayerStarVo;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.managers.TipsManager;

	/**
	 *球员基础item 
	 * @author Administrator
	 * 
	 */	
	public class PlayerBaseItem extends Sprite implements IComponent
	{
		/**
		 * 
		 */
		private var _skin:MovieClip;
		/**
		 *效果 
		 */
		public var frame:MovieClip;
		/**
		 *容器 
		 */
		public var contain:MovieClip;
		/**
		 *位置 
		 */
		public var _place:TextField;
		/**
		 *号码 
		 */
		public var _number:TextField;
		/**
		 *颜色 
		 */
		public var playerColorBg:MovieClip;
		/**
		 * 
		 */
		private var _data:Object;
		/**
		 *状态  
		 */
		public var buff:MovieClip;
		private var _select:Boolean;
		private var _callBack:Function;
		
		
		public function PlayerBaseItem()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			_skin = Reflection.createInstance("com.lz.commonUI.playerItem");
			this.addChild(_skin);
			frame = _skin.frame;
			_place = _skin._place;
			_number = _skin._number
			contain = _skin.contain;
			buff = _skin.buff;
			buff.visible = false;
			playerColorBg = _skin.playerColorBg;
			frame.visible = false;
			frame.mouseChildren = false;
			frame.mouseEnabled = false;
		}
		
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.CLICK,onMouseClick);
			this.addEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.addEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
		}
		public function onMouseRollOut(event:MouseEvent):void
		{
			TipsManager.hide();
			if(select)return;
			frame.visible = false;
		}
		
		public function onMouseRollOver(event:MouseEvent):void
		{
			if(data is PlayerVo)
			{
				TipsManager.show(TipsConst.PLAYERCARDTIPSBYPLAYER,{data:data,type:1},20,10,true);
			}else if(data is PlayerStarVo)
			{
				TipsManager.show(TipsConst.PLAYERCARDTIPS,data,20,10,true);
			}
			if(select)return;
			frame.visible = true;
		}
		
		public function onMouseClick(event:MouseEvent):void
		{
			if(data != null && callBack != null)
				callBack(this);
		}
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.removeEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
			this.removeEventListener(MouseEvent.CLICK,onMouseClick);
		}
		
		public function destroyView():void
		{
			removeEvtListener();
			reSet();
			DisplayObjectUtil.removeAllChildren(contain);
			if(this.parent)this.parent.removeChild(this);
			_skin = null;
			playerColorBg = null;
			_callBack = null;
			TipsManager.hide();
		}
		/**
		 *重置 
		 * 
		 */
		public function reSet():void
		{
			buff.visible = false;
			select = false;
			_place.text = "";
			_number.text = "";
			_data = null;
		}
		/**
		 *选中状态 
		 */
		public function get select():Boolean
		{
			return _select;
		}

		/**
		 * @private
		 */
		public function set select(value:Boolean):void
		{
			_select = value;
			if(_select)
			{
				frame.visible = true;
			}else
			{
				frame.visible = false;
			}
		}
		/**
		 *更新buff状态 
		 * 
		 */
		public function updataBuff():void
		{
			var vo:PlayerVo = data as PlayerVo;
			if(vo.status == 1)
			{
				buff.visible = false;
			}else
			{
				buff.visible = true;
			}
		}
		public function get data():Object
		{
			return _data;
		}
		
		public function set data(value:Object):void
		{
			_data = value;
			DisplayObjectUtil.removeAllChildren(contain);
			var bitmapData :BitmapData ;
			var bitmap :Bitmap
			if(value is PlayerVo)
			{
				
				var vo:PlayerVo = value as PlayerVo;
				_place.text = vo.place_String + "";
				_number.text = vo.number + "";
				if(vo.starVo == null)return;
				if(vo.status == 1)
				{
					buff.visible = false;
				}else
				{
					buff.visible = true;
				}
				bitmapData 	= vo.starVo.bitmapData;
				bitmap = new Bitmap(bitmapData);
				playerColorBg.gotoAndStop(vo.color);
				contain.addChild(bitmap);
			}else if(value is PlayerStarVo)
			{
				var staVo:PlayerStarVo =  value as PlayerStarVo
				bitmapData= staVo.bitmapData;
				bitmap = new Bitmap(bitmapData);
				playerColorBg.gotoAndStop(staVo.color);
				contain.addChild(bitmap);
			}
			addEvtListener();
		}
		public function get callBack():Function
		{
			return _callBack;
		}

		public function set callBack(value:Function):void
		{
			_callBack = value;
		}

	}
}